<template>
	<view>
		<swiper style="height: 440rpx;" :indicator-dots="newData.length>1" indicator-color="rgba(255, 98, 62, 0.35)" indicator-active-color="#ED4549" v-if="itemData.style.styleType==1">
			<swiper-item v-for="(item1,index1) in newData" :key="index1">
				<view class="diy-navbar" :style="{background:itemData.style.background}">
					<view class="item" v-for="(item, index) in item1" :key="index"
						:style="'width:'+item_width+';'" @click="gotoDetail(item)">
						<image :src="item.imgUrl" mode="widthFix"></image>
						<text class="gray3" :style="{color:item.color}">{{item.text}}</text>
					</view>
				</view>
			</swiper-item>
		</swiper>
		<!--图标入口-->
		<view class="diy-navbar" :style="{background:itemData.style.background}" v-if="itemData.style.styleType==0">
			<view class="item" v-for="(item, index) in itemData.data" :key="index" :style="'width:'+item_width+';'" @click="gotoDetail(item)">
				<image :src="item.imgUrl" mode="widthFix"></image>
				<text class="gray3" :style="{color:item.color}">{{item.text}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				newData:[],
				//单个宽度
				item_width: '25%'
			}
		},
		props: ['itemData'],
		created() {
			this.item_width = 100 / Math.abs(this.itemData.style.rowsNum) + '%';
			if(this.itemData.style.styleType==1){
				this.newData = this.chunkArray(this.itemData.data,Number(this.itemData.style.rowsNum)*2)
			}
		},
		methods: {
			chunkArray(array, size) {
				const result = [];
				for (let i = 0; i < array.length; i += size) {
					result.push(array.slice(i, i + size));
				}
				return result;
			},
			/*跳转页面*/
			gotoDetail(e) {
				this.gotoPage(e.linkUrl);
			}
		}
	}
</script>

<style>
	.diy-navbar {
		margin: 20rpx;
		padding: 30rpx 0;
		border-radius: 6rpx;
		background: #FFFFFF;
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;
	}

	.diy-navbar .item {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: 20rpx;
		width: 120rpx;
		height: 160rpx;
	}

	.diy-navbar .item image {
		width: 88rpx;
		height: 88rpx;
	}

	.diy-navbar .item text {
		display: block;
		text-overflow: ellipsis;
		white-space: nowrap;
		width: 100%;
		overflow: hidden;
		line-height: 66rpx;
		font-size: 26rpx;
		text-align: center;
	}
</style>